package com.itheima.jdsearch.controller;

import com.itheima.jdsearch.pojo.PageResult;
import com.itheima.jdsearch.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @作者 itcast
 * @创建日期 2020/11/21 17:36
 **/
@RestController
@RequestMapping("good")
public class SearchController {
    @Autowired
    SearchService searchService;

    /**
     * 商品搜索
     * @param page 当前页
     * @param pageSize 每页条数
     * @param keyword 关键词
     * @param price 价格区间 格式: 0-1000  1000-2000  3000 (代表3000以上)
     * @param sort 排序字段:  如 价格排序 值==> price
     * @param order 升序降序   true: 升序   false: 降序
     * @return
     */
    @GetMapping("search/{page}/{pageSize}")
    public PageResult search(@PathVariable("page") Integer page,
                             @PathVariable("pageSize") Integer pageSize,
                             @RequestParam String keyword,
                             @RequestParam(required = false) String price,
                             @RequestParam(required = false) String sort,
                             @RequestParam(required = false) boolean order){
        return searchService.search(keyword,page,pageSize,price,sort,order);
    }
}
